import http
import os,pdb
from .. import config

f=open('./sites/img_template.html','r')
headers,endings=f.read().split('<!--SPLIT-->')
f.close()

oneImg='''<img class="image" src="%s" onclick="window.open('%s');" />
'''

def viewAll(handler):
    images=os.listdir(config.image_path)
    html=headers
    for image in images:
        loadpath=os.path.join(config.image_path,image)
        html+=oneImg%(loadpath,loadpath)
    html+=endings
    handler.send_response(http.HTTPStatus.OK)
    handler.send_header('Content-type','html')
    handler.send_header('Content-Encoding','utf-8')
    handler.end_headers()
    handler.wfile.write(html.encode())

